home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
asm_n_z.zip
/
TSRDEMO2.ASM
< prev
next >
Wrap
Assembly Source File
|
1987-03-10
|
46KB
|
1,503 lines
page 60,132
;==============================================================================
; TSRDEMO2.ASM
; Thomas Brandenborg
; 87.02.11
;
; Sample demonstration of a safe approach for writing TSR programmes.
;
;------------------------------------------------------------------------------
; Copyright 1987 by Thomas Brandenborg. All Rights Reserved
; Written for uploading to Compuserve Forums by
;
; Thomas Brandenborg
; Lundbyesgade 11
; DK-8000 Aarhus C
; DENMARK
;
; This code is intended as a reference to users on Compuserve Forums
; on how to write Terminate-And-Stay resident programmes for Personal
; Cumputers running under DOS versions 2.00 and newer.
;
; The code is not part of any proprietary product, but is rather a
; demonstration of such techniques that may be used to write safe TSR
; programmes.
;
; All or part of it may, however, be used in other software products
; or otherwise distributed assuming the copyright holders Name & Address
; as listed above are included clearly and visibly in the documentation
; for such product.
;
; The copyright holder offers no warranty with this code whatsoever,
; including its fitness for any particular purpose. Neither shall he
; be liable for damages of any kind that may arise from its use.
;
;
; IF YOU THINK THIS CODE IS USEFUL:
;
; If you think this code has had some value to you, and in particular
; if you consider using all or parts of it in your own product, you
; may want to consider a smaller or larger donation to the author
; (Name & Address above) who spend his late night hours putting
; it together.
;
; As to the size of a such donation this is entirely up to your own
; judgement. It is suggested that you simply consider the value this
; code has had to you, the time you saved not having to write it your
; self... that should help you determine the right amount.
;
; Please notice that such donations are an entirely voluntary contribution.
; This holds true whatever your purpose is for using this code, and whatever
; the type of product and distribution you work with. The author has nothing
; against commercial software distribution and does not have any reason
; to restrict developers of commercial products in their use of this code.
;------------------------------------------------------------------------------
; COMPILING: masm tsrdemo2;
; LINKING: link tsrdemo2;
; exe2bin tsrdemo2 tsrdemo2.com
;------------------------------------------------------------------------------
; Revisions
; Brandenborg 87.02.14 Added copyright notice & checked comments
; Brandenborg 87.02.17 Added full AX value in Set Ext Err call
; Brandenborg 87.02.25 Went through to optimize things
; Brandenborg 87.02.28 Added auto INT28 invocation in INT16 handler
; Brandenborg 87.03.01 Added INT21 filter for recursion onto console stack
; Brandenborg 87.03.02 Final cleanup of comments etc.
; Brandenborg 87.03.10 INT28 handler chains AFTER popup actions
; InitPopup: INT21.33 (AL=2) not allowed for DOS 2.x
; InitPopup: Set ext err info uses all regs
;==============================================================================
;==============================================================================
; DEFINE BIOS DATA SEGMENT OFFSETS
;==============================================================================
BiosData segment at 40h
org 17h
KbFlag label byte ;current shift status bits
org 18h
KbFlag1 label byte ;current key status of toggle keys
BiosData ends
;==============================================================================
; DEFINE OFFSETS WITHIN BIOS EXTRA DATA SEGMENT
;==============================================================================
BiosXX segment at 50h
org 0
StatusByte label byte ;PrtSc status
BiosXX ends
ErrPrtSc equ -1 ;err during last PrtSc
InPrtSc equ 1 ;PrtSc in progress
;==============================================================================
; DEFINE OFFSETS WITHIN OUR PSP
;==============================================================================
Cseg segment byte public
org 2
TopSeg label word ;last seg in alloc block
org 2ch
EnvSeg label word ;seg of our environment copy
Cseg ends
;==============================================================================
; DOS COM-FILE ENTRY POINT
;==============================================================================
Cseg segment public byte
assume cs:Cseg, ds:nothing, es:nothing, ss:nothing
org 100h
ComEntry: jmp Init ;JMP to init at bottom of seg
;==============================================================================
; IDENTIFICATION CODES FOR THIS TSR (MUST BE UNIQUE FOR EACH CO-EXISTING TSR)
; HIGH BYTE OF GetId MUST NOT MATCH ANY AH REQUEST CODES FOR INT16H.
;==============================================================================
GetId equ 'tc' ;INT16h AX val to get MyId
MyId equ 'TC' ;ID of this TSR
;==============================================================================
; FLAGS AND PTRS FOR RESIDENT HANDLING
;==============================================================================
TsrMode db 0 ;bits for various modes
InInt08 equ 1 SHL 0 ;timer0 tick handler
InInt09 equ 1 SHL 1 ;keyboard handler
InInt13 equ 1 SHL 2 ;BIOS disk I/O
InInt28 equ 1 SHL 3 ;INT28 handler
In28Call equ 1 SHL 4 ;we have issued INT28
InPopup equ 1 SHL 5 ;popup routine activated
NewDos equ 1 SHL 6 ;DOS 2.x in use
InDosClr equ 1 SHL 7 ;InDos=0 at popup time
KeyMode db 0 ;bits for hotkey status
HotIsShift equ 1 SHL 0 ;hotkey is shift state
InHotMatch equ 1 SHL 1 ;so far keys match hotkey seq
HotKeyOn equ 1 SHL 2 ;full hotkey pressed
InDosPtr label dword ;seg:off of InDos flag
InDosOff dw 0
InDosSeg dw 0
CritErrPtr label dword ;seg:off of CritErr flag
CritErrOff dw 0
CritErrSeg dw 0
;==============================================================================
; DATA FOR INT09H HANDLER TO CHECK FOR HOTKEY COMBINATION
;==============================================================================
; ------------ EQU'S FOR BIT SHIFTS WITHIN KEYBOARD FLAGS
InsState equ 80h
CapsState equ 40h
NumState equ 20h
ScrollState equ 10h
AltShift equ 08h
CtlShift equ 04h
LeftShift equ 02h
RightShift equ 01h
InsShift equ 80h
CapsShift equ 40h
NumShift equ 20h
ScrollShift equ 10h
HoldState equ 08h
; ------------ SCAN CODES FOR VARIOUS SHIFT KEYS
LeftDown equ 42 ;scan code of left shift key
LeftUp equ LeftDown OR 80h
RightDown equ 54 ;scan code of right shift key
RightUp equ RightDown OR 80h
AltDown equ 56 ;scan code of alt key
AltUp equ AltDown OR 80h
CtlDown equ 29 ;scan code of ctrl key
CtlUp equ CtlDown OR 80h
; ------------ MISC KEYBOARD DATA
KbData equ 60h ;keyboard data input
;==============================================================================
; TO USE A SHIFT KEY COMBINATION AS HOT KEY:
; - SET THE FLAG HotIsShift IN KeyMode
; - DEFINE THE SHIFT STATUS BITS IN THE VARIABLE HotKeyShift
;
; TO USE A SERIES OF SCAN CODES AS HOT KEY:
; CLEAR THE FLAG HotIsShift IN KeyMode
; - INSERT THE MAKE AND BREAK SCAN CODES IN THE HotKeySeq STRING
; NOTE: WITH THIS DEMO IMPLEMENTATION YOU SHOULD NOT USE A HOT KEY
; SEQUENCE WHICH PRODUCES A KEY IN THE BIOS KEYBOARD QUEUE,
; SINCE THE KEY IS NOT REMOVED BEFORE CALLING THE POPUP ROUTINE.
;
; NOTE: HOTKEY TYPE AND CONTENTS OF HOTKEY VARIABLES MAY BE CHANGED AT RUN TIME
;==============================================================================
HotKeyShift db LeftShift OR RightShift ;shift state IF HotIsShift=FF
HotKeySeq db LeftDown,LeftUp,LeftDown,LeftUp
HotKeyLen equ $-HotKeySeq
HotIndex db 0 ;# key in seq to compare next
BetweenKeys db 0 ;timeout count between keys
KeyTimeOut equ 10 ;more ticks means not a hotkey
;==============================================================================
; DATA FOR INT08H HANDLER TO CHECK FOR POPUP
;==============================================================================